<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-11-17
 * Time: 上午 9:53
 */
defined('ByShopWWI') or exit('Access Invalid!');
class orderControl extends mobileMemberControl
{
    public function __construct() {
        parent::__construct();
    }

    /**
     * 购物车、直接购买第一步:选择收获地址和配置方式  OLD
     */
    public function buy_stepOp(){
        $cart_ids = $_POST['cart_ids'];
        if(empty($cart_ids))return;
        $model_cart = Model('cart');
        //购物车列表
        $cart_list  = $model_cart->listCart('db',array('buyer_id'=>$_SESSION['member_id'],'cart_id'=>array ('in',$_POST['cart_ids'])));
        foreach ($cart_list as $key => $cart_info) {
            if(!empty($cart_info['goods_id'])) {
                $goods_detail = Model('goods')->getGoodsInfoByID($cart_info['goods_id'],'goods_rate');
                $cart_info['goods_rate'] = $goods_detail['goods_rate'];
                $cart_info['goods_total_price'] = $cart_info['goods_price']*$cart_info['goods_num'];
            }else{
                $cart_info['goods_rate'] = 6;
            }
            $cart_list[$key] = $cart_info;
        }

        //输出用户默认收货地址
        $address_info = Model('address')->getDefaultAddressInfo(array('member_id'=>$_SESSION['member_id'],'is_default'=>1));

        Tpl::output('cart_goods_num',$model_cart->cart_goods_num);
        Tpl::output('cart_all_price',$model_cart->cart_all_price);
        Tpl::output('cart_list',$cart_list);
        Tpl::output('address_info',$address_info);

        Tpl::showpage('goods_order');
    }

    /**
     * 购物车、直接购买第一步:选择收获地址和配置方式
     */
    public function buy_step1Op(){
        $cart_id = explode(',', $_POST['cart_id']);
        $logic_buy = logic('buy');

        //得到会员等级
        $model_member = Model('member');
        $member_info = $model_member->getMemberInfoByID($_SESSION['member_id']);

        if ($member_info){
            $member_gradeinfo = $model_member->getOneMemberGrade(intval($member_info['member_exppoints']));
            $member_discount = $member_gradeinfo['orderdiscount'];
            $member_level = $member_gradeinfo['level'];
        } else {
            $member_discount = $member_level = 0;
        }

        //得到购买数据
        $result = $logic_buy->buyStep1($cart_id, $_POST['ifcart'], $_SESSION['member_id'], null,null,$member_discount,$member_level);


        if(!$result['state']) {
            //showError message
            return;
        } else {
            $result = $result['data'];
        }

        //整理数据
        $store_cart_list = array();
        $sum = 0;
        $goods_count = 0;
        foreach ($result['store_cart_list'] as $key => $value) {
            $store_cart_list[$key]['goods_list'] = $value;
            $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
            if(!empty($result['store_premiums_list'][$key])) {
                $result['store_premiums_list'][$key][0]['premiums'] = true;
                $result['store_premiums_list'][$key][0]['goods_total'] = 0.00;
                $store_cart_list[$key]['goods_list'][] = $result['store_premiums_list'][$key][0];
            }
            $store_cart_list[$key]['store_mansong_rule_list'] = $result['store_mansong_rule_list'][$key];
            //返回商城可用的代金券
            $store_cart_list[$key]['store_voucher_list'] = $result['store_voucher_list'][$key];
            $store_cart_list[$key]['store_voucher_info'] = array();
            if($store_cart_list[$key]['store_voucher_list']){
                $store_cart_list[$key]['store_voucher_info'] = array('voucher_price'=>$store_cart_list[$key]['store_voucher_list']['1']['voucher_price']);
            }
            if(!empty($result['cancel_calc_sid_list'][$key])) {
                $store_cart_list[$key]['freight'] = '0';
                $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
            } else {
                $store_cart_list[$key]['freight'] = '1';
            }
            $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
            $sum += $store_cart_list[$key]['store_goods_total'];
            $goods_count += count($store_cart_list[$key]['goods_list']);
        }

        $buy_list = array();
        $buy_list['store_cart_list'] = $store_cart_list;
        $buy_list['freight_hash'] = $result['freight_list'];
        $buy_list['address_info'] = $result['address_info'];
        $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
        $buy_list['vat_hash'] = $result['vat_hash'];
        $buy_list['inv_info'] = $result['inv_info'];
        $buy_list['available_predeposit'] = $result['available_predeposit'];
        $buy_list['available_rc_balance'] = $result['available_rc_balance'];
        if (is_array($result['rpt_list']) && !empty($result['rpt_list'])) {
            foreach ($result['rpt_list'] as $k => $v) {
                unset($result['rpt_list'][$k]['rpacket_id']);
                unset($result['rpt_list'][$k]['rpacket_end_date']);
                unset($result['rpt_list'][$k]['rpacket_owner_id']);
                unset($result['rpt_list'][$k]['rpacket_code']);
            }
        }
        $buy_list['rpt_list'] = $result['rpt_list'] ? $result['rpt_list'] : array();
        $buy_list['zk_list'] = $result['zk_list'];
        $buy_list['order_amount'] = $sum;
        $buy_list['rpt_info'] = '';
        $buy_list['address_api'] = $logic_buy->changeAddr($result['freight_list'], '1', '1', $_SESSION['member_id']);
        $buy_list['store_final_total_list'] = ncPriceFormat($sum);

        $address_info = Model('address')->getDefaultAddressInfo(array('member_id'=>$_SESSION['member_id'],'is_default'=>1));
        $buy_list['address_info'] =$address_info;

		//积分查询
        $obj_member = Model('member');
        $member_points=$obj_member->getMemberInfoByID($_SESSION['member_id'],'member_points');
        $points_money = (empty($member_points['member_points']) || $member_points['member_points']==0) ? 0 : ncPriceFormat($member_points['member_points']/100);
        Tpl::output('member_points', $member_points['member_points']);
        Tpl::output('points_money', $points_money);
        Tpl::output('cart_goods_num',$goods_count);
        Tpl::output('buy_list',$buy_list);
        Tpl::output('ifcart',$_POST['ifcart']);
        Tpl::output('cart_id',$_POST['cart_id']);

        $address_list = Model('address')->getAddressList(array('member_id'=>(int)$_SESSION['member_id']),'is_default DESC,address_id DESC');
        Tpl::output('address_list',$address_list);

        Tpl::showpage('goods_order');
    }

    /**
     * 购物车、直接购买第二步:保存订单入库，产生订单号，开始选择支付方式
     *
     */
    public function buy_step2Op() {
        $param = array();
        $param['ifcart'] = $_POST['ifcart'];
        $param['cart_id'] = explode(',', $_POST['cart_id']);
        $param['address_id'] = $_POST['address_id'];
        $param['vat_hash'] = $_POST['vat_hash'];
        $param['offpay_hash'] = $_POST['offpay_hash'];
        $param['offpay_hash_batch'] = $_POST['offpay_hash_batch'];
        $param['pay_name'] = $_POST['pay_name'];
        $param['invoice_id'] = $_POST['invoice_id'];
        $param['rpt'] = $_POST['rpt'];
        $param['tuoguan'] = $_POST['tuoguan'];
        $param['jfeng_use'] = $_POST['jfeng_use'];

        //处理代金券
        $voucher = array();
        $post_voucher = explode(',', $_POST['voucher']);
        if(!empty($post_voucher)) {
            foreach ($post_voucher as $value) {
                list($voucher_t_id, $store_id, $voucher_price) = explode('|', $value);
                $voucher[$store_id] = $value;
            }
        }
        $param['voucher'] = $voucher;

        //手机端暂时不做支付留言，页面内容太多了
        $param['pay_message'] = json_decode($_POST['pay_message']);
        $param['pd_pay'] = $_POST['pd_pay'];
        $param['rcb_pay'] = $_POST['rcb_pay'];
        $param['password'] = $_POST['password'];
        $param['fcode'] = $_POST['fcode'];
        $param['order_from'] = 2;
        $logic_buy = logic('buy');

        //得到会员等级
        $model_member = Model('member');
        $member_info = $model_member->getMemberInfoByID($this->member_info['member_id']);
        if ($member_info){
            $member_gradeinfo = $model_member->getOneMemberGrade(intval($member_info['member_exppoints']));
            $member_discount = $member_gradeinfo['orderdiscount'];
            $member_level = $member_gradeinfo['level'];
        } else {
            $member_discount = $member_level = 0;
        }
        $result = $logic_buy->buyStep2($param, $this->member_info['member_id'], $this->member_info['member_name'],$this->member_info['member_email'],$member_discount,$member_level);
        if(!$result['state']) {
            return;
        }

        $pay_sn = $result['data']['pay_sn'];
        $condition = array();
        $condition['pay_sn'] = $pay_sn;
        $order_info = Model('order')->getOrderInfo($condition);
       // $payment_list = Model('mb_payment')->getMbPaymentList();

        $pay_info['pay_amount'] = $order_info['order_amount'];
        $pay_info['member_available_pd'] = $this->member_info['available_predeposit'];
        $pay_info['member_available_rcb'] = $this->member_info['available_rc_balance'];

        $pay_info['member_paypwd'] = 1;
        if(empty($this->member_info['member_paypwd'])){
            $pay_info['member_paypwd'] = 0;
        }

        $pay_info['pay_sn'] = $order_info['pay_sn'];
        $pay_info['payed_amount'] = $order_info['pd_amount'];

        if($pay_info['payed_amount']>'0.00'){
            $pay_info['pay_amount'] = $pay_info['pay_amount']-$pay_info['payed_amount'];
        }

        $pay_in["pay_info"]=$pay_info;
       // $pay_in["pay_info"]["payment_list"]=$payment_list;

        Tpl::output('pay_in',$pay_in);

        Tpl::showpage('payment');
    }

    /**
     * 下单时支付页面
     */
    public function payOp() {
        $pay_sn = $_GET['pay_sn'];

        $condition = array();
        $condition['pay_sn'] = $pay_sn;
        $order_info = Model('order')->getOrderInfo($condition);
       // $payment_list = Model('mb_payment')->getMbPaymentList();

               $pay_info['pay_amount'] = $order_info['order_amount'];
        $pay_info['member_available_pd'] = $this->member_info['available_predeposit'];
        $pay_info['member_available_rcb'] = $this->member_info['available_rc_balance'];

        $pay_info['member_paypwd'] = 1;
        if(empty($this->member_info['member_paypwd'])){
            $pay_info['member_paypwd'] = 0;
        }

        $pay_info['pay_sn'] = $order_info['pay_sn'];
        $pay_info['payed_amount'] = $order_info['pd_amount'];

        if($pay_info['payed_amount']>'0.00'){
            $pay_info['pay_amount'] = $pay_info['pay_amount']-$pay_info['payed_amount'];
        }

        $pay_in["pay_info"]=$pay_info;
       // $pay_in["pay_info"]["payment_list"]=$payment_list;

        Tpl::output('pay_in',$pay_in);

        Tpl::showpage('payment');
    }
    
    //订单状态
    public function orderstateOp(){
    	$model_order = Model('order');

        //搜索
        $condition = array();
        $condition['buyer_id'] = $_SESSION['member_id'];
        if (preg_match('/^\d{10,20}$/',$_GET['order_sn'])) {
            $condition['order_sn'] = $_GET['order_sn'];
        }
        if (preg_match('/^\d{10,20}$/',$_GET['pay_sn'])) {
            $condition['pay_sn'] = $_GET['pay_sn'];
        }
        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
        $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
        $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']): null;
        if ($start_unixtime || $end_unixtime) {
            $condition['add_time'] = array('time',array($start_unixtime,$end_unixtime));
        }
        if ($_GET['state_type'] != '') {
            $condition['order_state'] = str_replace(
                    array('state_new','state_pay','state_send','state_success','state_noeval','state_cancel'),
                    array(ORDER_STATE_NEW,ORDER_STATE_PAY,ORDER_STATE_SEND,ORDER_STATE_SUCCESS,ORDER_STATE_SUCCESS,ORDER_STATE_CANCEL), $_GET['state_type']);
        }
        if ($_GET['state_type'] == 'state_new') {
            $condition['chain_code'] = 0;
        }
        if ($_GET['state_type'] == 'state_noeval') {
            $condition['evaluation_state'] = 0;
            $condition['order_state'] = ORDER_STATE_SUCCESS;
        }
        if ($_GET['state_type'] == 'state_notakes') {
            $condition['order_state'] = array('in',array(ORDER_STATE_NEW,ORDER_STATE_PAY));
            $condition['chain_code'] = array('gt',0);
        }

        //回收站
        if ($_GET['recycle']) {
            $condition['delete_state'] = 1;
        } else {
            $condition['delete_state'] = 0;
        }
        $order_list = $model_order->getOrderList($condition, 20, '*', 'order_id desc','', array('order_common','order_goods','store'));

        $model_refund_return = Model('refund_return');
        $order_list = $model_refund_return->getGoodsRefundList($order_list,1);//订单商品的退款退货显示

        //查询消费者保障服务
        if (C('contract_allow') == 1) {
            $contract_item = Model('contract')->getContractItemByCache();
        }

        //订单列表以支付单pay_sn分组显示
        $order_group_list = array();

        foreach ($order_list as $order_id => $order_info) {

            //显示取消订单
            $order_info['if_buyer_cancel'] = $model_order->getOrderOperateState('buyer_cancel',$order_info);

            //显示退款取消订单
            $order_info['if_refund_cancel'] = $model_order->getOrderOperateState('refund_cancel',$order_info);

            //显示投诉
            $order_info['if_complain'] = $model_order->getOrderOperateState('complain',$order_info);

            //显示收货
            $order_info['if_receive'] = $model_order->getOrderOperateState('receive',$order_info);

            //显示锁定中
            $order_info['if_lock'] = $model_order->getOrderOperateState('lock',$order_info);

            //显示物流跟踪
            $order_info['if_deliver'] = $model_order->getOrderOperateState('deliver',$order_info);

            //显示评价
            $order_info['if_evaluation'] = $model_order->getOrderOperateState('evaluation',$order_info);

            // 显示追加评价
            $order_info['if_evaluation_again'] = $model_order->getOrderOperateState('evaluation_again',$order_info);

            //显示删除订单(放入回收站)
            $order_info['if_delete'] = $model_order->getOrderOperateState('delete',$order_info);

            //显示永久删除
            $order_info['if_drop'] = $model_order->getOrderOperateState('drop',$order_info);

            //显示还原订单
            $order_info['if_restore'] = $model_order->getOrderOperateState('restore',$order_info);

            if(!empty($order_info['refund_list'])){
            	foreach($order_info['refund_list'] as $refund){
            		$refund_all = $refund;
            		continue;
            	}
            }else{
            	$refund_all = array();
            }
            
            if (!empty($refund_all) && $refund_all['seller_state'] < 3) {//订单全部退款商家审核状态:1为待审核,2为同意,3为不同意
               if($refund_all['refund_type']==1){
            	$order_info['refund'] = $refund_all;
               }elseif($refund_all['refund_type']==2){
               	$order_info['return'] = $refund_all;
               }
            }
            $model_product = Model("goods");
            if (is_array($order_info['extend_order_goods'])) {
                foreach ($order_info['extend_order_goods'] as $value) {
                    $value['image_60_url'] = cthumb($value['goods_image'], 60, $value['store_id']);
                    $value['image_240_url'] = cthumb($value['goods_image'], 240, $value['store_id']);
                    $value['goods_type_cn'] = orderGoodsType($value['goods_type']);
                    $value['goods_url'] = urlShop('goods','index',array('goods_id'=>$value['goods_id']));
                    //处理消费者保障服务
                    if (trim($value['goods_contractid']) && $contract_item) {
                        $goods_contractid_arr = explode(',',$value['goods_contractid']);
                        foreach ((array)$goods_contractid_arr as $gcti_v) {
                            $value['contractlist'][] = $contract_item[$gcti_v];
                        }
                    }
                    $product_info = $model_product->getGoodsInfo(array('goods_id'=>$value['goods_id']));
                    $value['goods_jingle'] = $product_info['goods_jingle'];
                    $value['year_rate'] = $product_info['year_rate'];
                    $value['year_limit'] = $product_info['year_limit'];
                    if ($value['goods_type'] == 5) {
                        $order_info['zengpin_list'][] = $value;
                    } else {
                        $order_info['goods_list'][] = $value;
                    }   
                }
            }

            if (empty($order_info['zengpin_list'])) {
                $order_info['goods_count'] = count($order_info['goods_list']);
            } else {
                $order_info['goods_count'] = count($order_info['goods_list']) + 1;
            }

            //取得其它订单类型的信息
            $model_order->getOrderExtendInfo($order_info);

            //如果有在线支付且未付款的订单则显示合并付款链接
            $_flag = ($order_info['order_state'] == ORDER_STATE_NEW && $order_info['order_type'] == 1) ||
            ($order_info['order_state'] == ORDER_STATE_NEW && $order_info['order_type'] == 3 && $order_info['payment_code'] == 'online');
            if ($_flag) {
                $order_group_list[$order_info['pay_sn']]['pay_amount'] += $order_info['order_amount']-$order_info['pd_amount']-$order_info['rcb_amount'];
            }

            $order_group_list[$order_info['pay_sn']]['order_list'][] = $order_info;
        }
        if(empty($order_group_list)){
        	$model_goods = Model('goods');
            $date['gc_name']=array(array('like','店长私藏%'),array('like','传统文化%'),array('like','送礼佳品%'),array('like',
            '摆件专区%'),array('like','壁挂专区%'),array('like','茶具专区%'), 'or');
            $goods_class_list= Model('goods_class')->goods_list($date);

            $store_id = empty($_SESSION['store_id'])?1:$_SESSION['store_id'];
        	$goods_list_sl = $model_goods->getGoodsGcStoreRandList($goods_class_list['goods'], $store_id);//送礼佳品，馈赠礼品
        	Tpl::output('goods_list_sl',$goods_list_sl);
        }
        Tpl::output('order_group_list',$order_group_list);
        Tpl::output('show_page',$model_order->showpage());
    	
        Tpl::showpage('orderstate');
    } 
    

    /**
     * 买家订单状态操作
     *
     */
    public function change_stateOp() {
        $state_type = $_GET['state_type'];
        $order_id   = intval($_GET['order_id']);

        $model_order = Model('order');

        $condition = array();
        $condition['order_id'] = $order_id;
        $condition['buyer_id'] = $_SESSION['member_id'];
        $order_info = $model_order->getOrderInfo($condition);

        //取得其它订单类型的信息
        $model_order->getOrderExtendInfo($order_info);
        if(empty($_POST))$_POST = array();
        if($_GET['state_type'] == 'order_cancel') {
            $result = $this->_order_cancel($order_info, $_POST);
        } else if ($_GET['state_type'] == 'order_receive') {
            $result = $this->_order_receive($order_info, $_POST);
        } else if (in_array($_GET['state_type'],array('order_delete','order_drop','order_restore'))){
            $result = $this->_order_recycle($order_info, $_GET);
        } else {
            exit();
        }

        if(!$result['state']) {
            output_data(array($result['msg'],'','error','',5));
        } else {
            output_data(array($result['msg'],'reload','js'));
        }
    }
    
 /**
     * 取消订单
     */
    private function _order_cancel($order_info, $post) {
        if (empty($_POST)) {
            Tpl::output('order_info', $order_info);
            Tpl::showpage('member_order.cancel','null_layout');
            exit();
        } else {
            $model_order = Model('order');
            $logic_order = Logic('order');
            $if_allow = $model_order->getOrderOperateState('buyer_cancel',$order_info);
            if (!$if_allow) {
                return callback(false,'无权操作');
            }
          /*  if (TIMESTAMP - 86400 < $order_info['api_pay_time']) {
                $_hour = ceil(($order_info['api_pay_time']+86400-TIMESTAMP)/3600);
                return callback(false,'该订单曾尝试使用第三方支付平台支付，须在'.$_hour.'小时以后才可取消');
            }*/

            $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
            if ($order_info['order_type'] != 2) {
                $cancel_condition = array();
                if ($order_info['payment_code'] != 'offline') {
                    $cancel_condition['order_state'] = ORDER_STATE_NEW;
                }
                $result = $logic_order->changeOrderStateCancel($order_info,'buyer', $_SESSION['member_name'], $msg,true,$cancel_condition);
            } else {
                //取消预定订单
                $result = Logic('order_book')->changeOrderStateCancel($order_info,'buyer', $_SESSION['member_name'], $msg);
            }
            return $result;
        }
    }

    /**
     * 收货
     */
    private function _order_receive($order_info, $post) {
            $model_order = Model('order');
            $logic_order = Logic('order');
            $if_allow = $model_order->getOrderOperateState('receive',$order_info);
            if (!$if_allow) {
                return callback(false,'无权操作');
            }

            return $logic_order->changeOrderStateReceive($order_info,'buyer',$_SESSION['member_name'],'签收了货物');
        
    }

    /**
     * 回收站
     */
    private function _order_recycle($order_info, $get) {
        $model_order = Model('order');
        $logic_order = Logic('order');
        $state_type = str_replace(array('order_delete','order_drop','order_restore'), array('delete','drop','restore'), $_GET['state_type']);
        $if_allow = $model_order->getOrderOperateState($state_type,$order_info);
        if (!$if_allow) {
            return callback(false,'无权操作');
        }

        return $logic_order->changeOrderStateRecycle($order_info,'buyer',$state_type);
    }
    
    public function refundOp(){
    	Language::read('member_member_index');
        $model_refund = Model('refund_return');
        $condition = array();
        $reason_list = $model_refund->getReasonList($condition);//退款退货原因
        Tpl::output('reason_list',$reason_list);
        $order_id = intval($_GET['order_id']);
        $goods_id = intval($_GET['goods_id']);//订单商品表编号
        if ($order_id < 1) {//参数验证
            echo "订单参数提交错误";exit;
        }
        $condition = array();
        $condition['buyer_id'] = $_SESSION['member_id'];
        $condition['order_id'] = $order_id;
        $order = $model_refund->getRightOrderList($condition, $goods_id);
        $order_id = $order['order_id'];
        $order_amount = $order['order_amount'];//订单金额
        $order_refund_amount = $order['refund_amount'];//订单退款金额
        $goods_list = $order['goods_list'];
        $goods = $goods_list[0];
        $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
        if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
            $goods_pay_price = $order_amount - $order_refund_amount;
            $goods['goods_pay_price'] = $goods_pay_price;
        }
        Tpl::output('goods',$goods);

        $goods_id = $goods['rec_id'];
        $condition = array();
        $condition['buyer_id'] = $order['buyer_id'];
        $condition['order_id'] = $order['order_id'];
        $condition['order_goods_id'] = $goods_id;
        $condition['seller_state'] = array('lt','3');
        $refund_list = $model_refund->getRefundReturnList($condition);
      
        $refund = array();
        if (!empty($refund_list) && is_array($refund_list)) {
            $refund = $refund_list[0];
        }  
        $refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货

        if ($refund['refund_id'] > 0) {//检查订单状态,防止页面刷新不及时造成数据错误
            echo "退货单已存在";
            redirect('index.php?act=order&op=view_refund&refund_id='.$refund['refund_id']);
            exit;
        }
        //if($refund_state == 0){
          //echo "请检查订单";exit;
        //}
        if (!empty($_POST) && $goods_id > 0){
            $refund_array = array();
            $refund_amount = floatval($_POST['refund_amount']);//退款金额
            if (($refund_amount < 0) || ($refund_amount > $goods_pay_price)) {
                $refund_amount = $goods_pay_price;
            }
            $goods_num = intval($_POST['goods_num']);//退货数量
            if (($goods_num < 0) || ($goods_num > $goods['goods_num'])) {
                $goods_num = 1;
            }
            $refund_array['reason_info'] = '';
            $reason_id = intval($_POST['reason_id']);//退货退款原因
            $refund_array['reason_id'] = $reason_id;
            $reason_array = array();
            $reason_array['reason_info'] = '其他';
            $reason_list[0] = $reason_array;
            if (!empty($reason_list[$reason_id])) {
                $reason_array = $reason_list[$reason_id];
                $refund_array['reason_info'] = $reason_array['reason_info'];
            }

            $pic_array = array();
            $pic_array['buyer'] = $this->upload_pic();//上传凭证
            $info = serialize($pic_array);
            $refund_array['pic_info'] = $info;

            $model_trade = Model('trade');
            $order_paid = $model_trade->getOrderState('order_paid');//订单状态20:已付款
            $order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
            if ($order['order_state'] == $order_shipped||$order['order_state'] == $order_paid) {
                $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
            }
            $refund_array['refund_type'] = $_POST['refund_type'];//类型:1为退款,2为退货
            $show_url = 'index.php?act=member_return&op=index';
            $refund_array['return_type'] = '1';//退货类型:1为不用退货,2为需要退货
            if ($refund_array['refund_type'] != '2') {
                $refund_array['refund_type'] = '1';
                $refund_array['return_type'] = '1';
                $show_url = 'index.php?act=member_refund&op=index';
            }
            $refund_array['reason_info'] = '取消订单，全部退款';
            $refund_array['goods_name'] = '订单商品全部退款';
            $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
            $refund_array['refund_amount'] = ncPriceFormat($refund_amount);
            $refund_array['goods_num'] = $goods_num;
            $refund_array['buyer_message'] = $_POST['buyer_message'];
            $refund_array['add_time'] = time();
            $state = $model_refund->addRefundReturn($refund_array,$order,$goods);

            if ($state) {
                if ($order['order_state'] == $order_shipped||$order['order_state'] == $order_paid) {
                    $model_refund->editOrderLock($order_id);
                }
                echo Language::get('nc_common_save_succ');
                redirect('index.php?act=order&op=orderstate');
            } else {
                echo Language::get('nc_common_save_fail');
            }
        }
        Tpl::showpage('refund');
    }
    
    public function returnOp(){
        $model_order = Model('order');
        $model_trade = Model('trade');
        $model_refund = Model('refund_return');
        $order_id = intval($_GET['order_id']);
        $condition = array();
        $condition['buyer_id'] = $_SESSION['member_id'];
        $condition['order_id'] = $order_id;
        $order = $model_refund->getRightOrderList($condition);
        
        //禁止退款金额
        $lock_amount = Logic('order_book')->getDepositAmount($order);
        $order['allow_refund_amount'] = $order['order_amount'] - $lock_amount;
        Tpl::output('order',$order);
        $goods_list = $order['goods_list'];
        $goods = $goods_list[0];
        $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
        $order_amount = $order['order_amount'];
        if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
            $goods_pay_price = $order_amount - $order_refund_amount;
            $goods['goods_pay_price'] = $goods_pay_price;
        }
        Tpl::output('goods',$goods);
        $order_amount = $order['allow_refund_amount'];//订单金额
        $condition = array();
        $condition['buyer_id'] = $order['buyer_id'];
        $condition['order_id'] = $order['order_id'];
        $condition['goods_id'] = '0';
        $condition['seller_state'] = array('lt','3');
        $refund_list = $model_refund->getRefundReturnList($condition);
        $refund = array();
        if (!empty($refund_list) && is_array($refund_list)) {
            $refund = $refund_list[0];
        }
        $order_paid = $model_trade->getOrderState('order_paid');//订单状态20:已付款
        $payment_code = $order['payment_code'];//支付方式
        $order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
        if ($refund['refund_id'] > 0 || $order['order_state'] != $order_shipped || $payment_code == 'offline') {//检查订单状态,防止页面刷新不及时造成数据错误
             echo "参数提交错误";exit;
        }
        if (chksubmit()) {
            $refund_array = array();
            $refund_array['refund_type'] = '2';//类型:1为退款,2为退货
            $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
            $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
            $refund_array['goods_id'] = '0';
            $refund_array['order_goods_id'] = '0';
            $refund_array['reason_id'] = '0';
            $refund_array['reason_info'] = '退货退款';
            $refund_array['goods_name'] = '订单商品退货退款';
            $refund_array['refund_amount'] = ncPriceFormat($order_amount);
            $refund_array['buyer_message'] = $_POST['buyer_message'];
            $refund_array['add_time'] = time();

            $pic_array = array();
            $pic_array['buyer'] = $this->upload_pic();//上传凭证
            $info = serialize($pic_array);
            $refund_array['pic_info'] = $info;
            $state = $model_refund->addRefundReturn($refund_array,$order);

            if ($state) {
                $model_refund->editOrderLock($order_id);
                showDialog(Language::get('nc_common_save_succ'),'index.php?act=member_refund&op=index','succ');
            } else {
                showDialog(Language::get('nc_common_save_fail'),'reload','error');
            }
        }
        Tpl::showpage('return');
    }
    
    /**
     * 上传凭证
     *
     */
    private function upload_pic() {
        $refund_pic = array();
        $refund_pic[1] = 'refund_pic1';
        $refund_pic[2] = 'refund_pic2';
        $refund_pic[3] = 'refund_pic3';
        $pic_array = array();
        $upload = new UploadFile();
        $dir = ATTACH_PATH.DS.'refund'.DS;
        $upload->set('default_dir',$dir);
        $upload->set('allow_type',array('jpg','jpeg','gif','png'));
        $count = 1;
        foreach($refund_pic as $pic) {
            if (!empty($_FILES[$pic]['name'])){
                $result = $upload->upfile($pic);
                if ($result){
                    $pic_array[$count] = $upload->file_name;
                    $upload->file_name = '';
                } else {
                    $pic_array[$count] = '';
                }
            }
            $count++;
        }
        return $pic_array;
    }
    /**
     * 查看退款
     */
    public function view_refundOp(){
    	$model_refund = Model('refund_return');
        $condition = array();
        $condition['buyer_id'] = $_SESSION['member_id'];
        $condition['refund_id'] = intval($_GET['refund_id']);
        $refund_list = $model_refund->getRefundList($condition);
        $refund = $refund_list[0];
        Tpl::output('refund',$refund);
        $info['buyer'] = array();
        if(!empty($refund['pic_info'])) {
            $info = unserialize($refund['pic_info']);
        }
        Tpl::output('pic_list',$info['buyer']);
        $detail_array = $model_refund->getDetailInfo(array('refund_id'=> $refund['refund_id']));
        Tpl::output('detail_array',$detail_array);
        $condition = array();
        $condition['order_id'] = $refund['order_id'];
        $model_refund->getRightOrderList($condition, $refund['order_goods_id']);
        
        //get order info
        $model_order = Model("order");
        $order_id = $refund['order_id'];
        $order_info = $model_order->getOrderInfo(array('order_id'=>$order_id));
        Tpl::output('order_info',$order_info);
        Tpl::showpage('refund_detail');
    }
    
    /**
     * 查看退货
     */
    public function view_returnOp(){
    	$model_refund = Model('refund_return');
        $condition = array();
        $condition['buyer_id'] = $_SESSION['member_id'];
        $condition['refund_id'] = intval($_GET['return_id']);
        $refund_list = $model_refund->getReturnList($condition);
        $refund = $refund_list[0];
        Tpl::output('refund',$refund);
        $info['buyer'] = array();
        if(!empty($refund['pic_info'])) {
            $info = unserialize($refund['pic_info']);
        }
        Tpl::output('pic_list',$info['buyer']);
        $detail_array = $model_refund->getDetailInfo(array('refund_id'=> $refund['refund_id']));
        Tpl::output('detail_array',$detail_array);
        $condition = array();
        $condition['order_id'] = $refund['order_id'];
        $model_refund->getRightOrderList($condition, $refund['order_goods_id']);
        
        //get order info
        $model_order = Model("order");
        $order_id = $refund['order_id'];
        $order_info = $model_order->getOrderInfo(array('order_id'=>$order_id));
        Tpl::output('order_info',$order_info);
        
        //express
        $model_express = Model('express');
    	$express_list = $model_express->getExpressList();
    	Tpl::output('express_list',$express_list);
        Tpl::showpage('return_detail');
    }
    
    /**
     * 退货单录入
     */
    public function return_logisticsOp(){
    	$model_express = Model('express');
    	$express_list = $model_express->getExpressList();
    	if(chksubmit()){
    		 $condition = array();
             $condition['refund_id'] = intval($_POST['return_id']);
    		
            $model_refund = Model('refund_return'); 
    		$refund_array = array();
            $refund_array['ship_time'] = time();
            $refund_array['delay_time'] = time();
            $refund_array['express_id'] = $_POST['express_id'];
            $refund_array['invoice_no'] = $_POST['shipping_code'];
            $refund_array['goods_state'] = '2';
            $state = $model_refund->editRefundReturn($condition, $refund_array);
            redirect('index.php?act=order&op=orderstate');
    	}
    	
    	
    	Tpl::output('return_id',(int)$_GET['return_id']);
    	Tpl::output('order_id',(int)$_GET['order_id']);
    	Tpl::output('express_list',$express_list);
    	Tpl::showpage('refund_logistics');
    }
    
    /*
     * 取消退款退货单
     */
    public function cancel_refundOp(){
    	$refund_id = (int)$_GET['refund_id'];
    	$model_refund = Model('refund_return');
    	$refund = $model_refund->table('refund_return')->where(array('refund_id'=>$refund_id))->select();
    	$order_id = $refund[0]['order_id'];
    	if($order_id){
    		$model_refund->editOrderUnlock($order_id);
    		$model_refund->table('refund_return')->where(array('refund_id'=>$refund_id))->delete();
    		redirect('index.php?act=order&op=orderstate');
    	}
    }
    
    //商品评论
    public function goods_commentOp(){
        $order_id = intval($_GET['order_id']);
        if (!$order_id){
            output_error('参数错误');
        }

        $model_order = Model('order');
        $model_store = Model('store');
        $model_evaluate_goods = Model('evaluate_goods');
        $model_evaluate_store = Model('evaluate_store');

        //获取订单信息
        $order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
        //判断订单身份
        if($order_info['buyer_id'] != $_SESSION['member_id']) {
            output_error('非成员订单');
        }
        //订单为'已收货'状态，并且未评论
        $order_info['evaluate_able'] = $model_order->getOrderOperateState('evaluation',$order_info);
        if (empty($order_info) || !$order_info['evaluate_able']){
            output_error('订单状态异常');
        }

        //查询商城信息
        $store_info = $model_store->getStoreInfoByID($order_info['store_id']);
        if(empty($store_info)){
            output_error('商城状态异常');
        }

        //获取订单商品
        $order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id));
        if(empty($order_goods)){
            output_error('商品状态异常');
        }

        //判断是否提交
        if (!empty($_POST)){
            $evaluate_goods_array = array();
            $goodsid_array = array();
            $member_id = $_SESSION['member_id'];
            foreach ($order_goods as $value){
            	//处理上传图片
            	/*if(!empty($_FILES)){
            		$upload = new UploadFile();
            		$upload->set('thumb_width', 500);
            		$upload->set('thumb_height',499);
                    $upload->set('ifremove',true);
                    $upload->set('thumb_ext','_240');
            		$upload->set('default_dir',ATTACH_MALBUM.DS.$member_id);
            		$_POST['goods'][$value['rec_id']]['evaluate_image'] = array();
            		for($i=1;$i<=3;$i++){
            			if (!empty($_FILES['file'.$i]['tmp_name'])){
            				$result = $upload->upfile('file'.$i);
            				if (!$result){
//            					showMessage($upload->error,'','html','error');
                                echo "<script> alert('图片上传失败');location.reload();</script>";
            				}else{
            					$_POST['goods'][$value['rec_id']]['evaluate_image'][] = $member_id.'_'.str_ireplace('_240.','.',$upload->thumb_image);//去除UPLOAD_SITE_URL.DS.ATTACH_MALBUM.DS.
            				}
            			}
            		}
            	}*/




                //如果未评分，默认为5分
                $evaluate_score = intval($_POST['goods'][$value['rec_id']]['score']);
                if($evaluate_score <= 0 || $evaluate_score > 5) {
                    $evaluate_score = 5;
                }
                //默认评语
                $evaluate_comment = $_POST['goods'][$value['rec_id']]['comment'];
                if(empty($evaluate_comment)) {
                    $evaluate_comment = '不错哦';
                }
                
                $geval_image = '';
                if (isset($_POST['imgitem']) && is_array($_POST['imgitem'])) {
                    foreach ($_POST['imgitem'] as $val) {
                        if(!empty($val)) {
                            $geval_image .= $val . ',';
                        }
                    }
                }
                $geval_image = rtrim($geval_image, ',');
                
                $evaluate_goods_info = array();
                $evaluate_goods_info['geval_orderid'] = $order_id;
                $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
                $evaluate_goods_info['geval_ordergoodsid'] = $value['rec_id'];
                $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
                $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
                $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
                $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
                $evaluate_goods_info['geval_scores'] = $evaluate_score;
                $evaluate_goods_info['geval_content'] = $evaluate_comment;
                $evaluate_goods_info['geval_isanonymous'] = $_POST['goods'][$value['rec_id']]['anony']?1:0;
                $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
                $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
                $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
                $evaluate_goods_info['geval_frommemberid'] = $_SESSION['member_id'];
                $evaluate_goods_info['geval_frommembername'] = $_SESSION['member_name'];
                $evaluate_goods_info['geval_image'] = $geval_image;
                $evaluate_goods_info['geval_content_again'] = '';
                $evaluate_goods_info['geval_image_again'] = '';
                $evaluate_goods_info['geval_explain_again'] = '';

                $evaluate_goods_array[] = $evaluate_goods_info;

                $goodsid_array[] = $value['goods_id'];
            }
            $model_evaluate_goods->addEvaluateGoodsArray($evaluate_goods_array, $goodsid_array);

            $store_desccredit = intval($_POST['store_desccredit']);
            if($store_desccredit <= 0 || $store_desccredit > 5) {
                $store_desccredit= 5;
            }
            $store_servicecredit = intval($_POST['store_servicecredit']);
            if($store_servicecredit <= 0 || $store_servicecredit > 5) {
                $store_servicecredit = 5;
            }
            $store_deliverycredit = intval($_POST['store_deliverycredit']);
            if($store_deliverycredit <= 0 || $store_deliverycredit > 5) {
                $store_deliverycredit = 5;
            }
            //添加商城评价
            if (!$store_info['is_own_shop']) {
                $evaluate_store_info = array();
                $evaluate_store_info['seval_orderid'] = $order_id;
                $evaluate_store_info['seval_orderno'] = $order_info['order_sn'];
                $evaluate_store_info['seval_addtime'] = time();
                $evaluate_store_info['seval_storeid'] = $store_info['store_id'];
                $evaluate_store_info['seval_storename'] = $store_info['store_name'];
                $evaluate_store_info['seval_memberid'] = $_SESSION['member_id'];
                $evaluate_store_info['seval_membername'] = $_SESSION['member_name'];
                $evaluate_store_info['seval_desccredit'] = $store_desccredit;
                $evaluate_store_info['seval_servicecredit'] = $store_servicecredit;
                $evaluate_store_info['seval_deliverycredit'] = $store_deliverycredit;
            }
            $model_evaluate_store->addEvaluateStore($evaluate_store_info);

            //更新订单信息并记录订单日志
            $state = $model_order->editOrder(array('evaluation_state'=>1), array('order_id' => $order_id));
            $model_order->editOrderCommon(array('evaluation_time'=>TIMESTAMP), array('order_id' => $order_id));
            if ($state){
                $data = array();
                $data['order_id'] = $order_id;
                $data['log_role'] = 'buyer';
                $data['log_msg'] = L('order_log_eval');
                $model_order->addOrderLog($data);
            }

            //添加会员积分
            if (C('points_isuse') == 1){
                $points_model = Model('points');
                $points_model->savePointsLog('comments',array('pl_memberid'=>$_SESSION['member_id'],'pl_membername'=>$_SESSION['member_name']));
            }
            //添加会员经验值
            Model('exppoints')->saveExppointsLog('comments',array('exp_memberid'=>$_SESSION['member_id'],'exp_membername'=>$_SESSION['member_name']));;

            redirect('index.php?act=order&op=orderstate');
        } else {
            for ($i = 0, $j = count($order_goods); $i < $j; $i++) {
                $order_goods[$i]['goods_image_url'] = cthumb($order_goods[$i]['goods_image'], 265, $store_info['store_id']);
            }
            
            //处理积分、经验值计算说明文字
            $ruleexplain = '';
            $exppoints_rule = C("exppoints_rule")?unserialize(C("exppoints_rule")):array();
            $exppoints_rule['exp_comments'] = intval($exppoints_rule['exp_comments']);
            $points_comments = intval(C('points_comments'));
            if ($exppoints_rule['exp_comments'] > 0 || $points_comments > 0){
                $ruleexplain .= '评价完成将获得';
                if ($exppoints_rule['exp_comments'] > 0){
                    $ruleexplain .= (' “'.$exppoints_rule['exp_comments'].'经验值”');
                }
                if ($points_comments > 0){
                    $ruleexplain .= (' “'.$points_comments.'积分”');
                }
                $ruleexplain .= '。';
            }
            Tpl::output('ruleexplain', $ruleexplain);
    
            $model_sns_alumb = Model('sns_album');
            $ac_id = $model_sns_alumb->getSnsAlbumClassDefault($_SESSION['member_id']);
            Tpl::output('ac_id', $ac_id);
            
            //不显示左菜单
            Tpl::output('order_info',$order_info);
            Tpl::output('order_goods',$order_goods);
            Tpl::output('store_info',$store_info);
            Tpl::showpage('goods_comment');
        } 
    }
    
    /**
     * 物流跟踪
     */
    public function search_deliverOp(){
        Language::read('member_member_index');
        $lang   = Language::getLangContent();
        $order_id   = intval($_GET['order_id']);
        if ($order_id <= 0) {
           echo "订单ID参数错误";exit;
        }

        $model_order    = Model('order');
        $condition['order_id'] = $order_id;
        $condition['buyer_id'] = $_SESSION['member_id'];
        $order_info = $model_order->getOrderInfo($condition,array('order_common','order_goods'));
        if (empty($order_info) || !in_array($order_info['order_state'],array(ORDER_STATE_SEND,ORDER_STATE_SUCCESS))) {
            echo '未找到信息';exit;
        }
        Tpl::output('order_info',$order_info);

        //卖家信息
        $model_store    = Model('store');
        $store_info     = $model_store->getStoreInfoByID($order_info['store_id']);
        Tpl::output('store_info',$store_info);

        //卖家发货信息
        $daddress_info = Model('daddress')->getAddressInfo(array('address_id'=>$order_info['extend_order_common']['daddress_id']));
        Tpl::output('daddress_info',$daddress_info);

        //取得配送公司代码
        $express = rkcache('express',true);
        Tpl::output('e_code',$express[$order_info['extend_order_common']['shipping_express_id']]['e_code']);
        Tpl::output('e_name',$express[$order_info['extend_order_common']['shipping_express_id']]['e_name']);
        Tpl::output('e_url',$express[$order_info['extend_order_common']['shipping_express_id']]['e_url']);
        Tpl::output('shipping_code',$order_info['shipping_code']);

        Tpl::output('left_show','order_view');
        Tpl::showpage('logistics_detail');
    }

    /**
     * 从第三方取快递信息
     *
     */
    public function get_expressOp(){

        $content = Model('express')->get_express($_GET['e_code'], $_GET['shipping_code']);

        $output = array();
        foreach ($content as $k=>$v) {
            if ($v['time'] == '') continue;
            $output[]= $v['time'].'&nbsp;&nbsp;'.$v['context'];
        }
        if (empty($output)) exit(json_encode(false));
        echo json_encode($output);
    }
    
    public function order_detailOp(){
    	$order_id   = intval($_GET['order_id']);
        if ($order_id <= 0) {
           echo "订单ID参数错误";exit;
        }

        $model_order    = Model('order');
        $condition['order_id'] = $order_id;
        $condition['buyer_id'] = $_SESSION['member_id'];
        $order_info = $model_order->getOrderInfo($condition,array('order_common','order_goods'));
        if (empty($order_info)) {
            echo '未找到信息';exit;
            // || !in_array($order_info['order_state'],array(ORDER_STATE_SEND,ORDER_STATE_SUCCESS))
        }
        Tpl::output('order_info',$order_info);
        
        $model_goods = Model('goods');
        $date['gc_name']=array(array('like','店长私藏%'),array('like','传统文化%'),array('like','送礼佳品%'),array('like',
            '摆件专区%'),array('like','壁挂专区%'),array('like','茶具专区%'), 'or');
        $goods_class_list= Model('goods_class')->goods_list($date);

        $store_id = empty($_SESSION['store_id'])?1:$_SESSION['store_id'];
        $goods_list_sl = $model_goods->getGoodsGcStoreRandList($goods_class_list['goods'], $store_id);//送礼佳品，馈赠礼品
        Tpl::output('goods_list_sl',$goods_list_sl);
    	
    	Tpl::showpage('order_detail');
    }


    /** hyy 3.31
     * 上传图片
     *
     * @param
     * @return
     */
    public function swfuploadOp() {
        /**
         * 读取语言包
         */
        Language::read('sns_home');
        $lang   = Language::getLangContent();
        $member_id  = $_SESSION['member_id'];
        $class_id   = intval($_POST['category_id']);
        if ($member_id <= 0 && $class_id <= 0){
            echo json_encode(array('state'=>'false','message'=>Language::get('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
            exit;
        }

        $model = Model();
        // 验证图片数量
        $count = $model->table('sns_albumpic')->where(array('member_id'=>$member_id))->count();
        if(C('malbum_max_sum') != 0 && $count >= C('malbum_max_sum')){
            echo json_encode(array('state'=>'false','message'=>Language::get('sns_upload_img_max_num_error'), 'origin_file_name' => $_FILES["file"]["name"]));
            exit;
        }

        /**
         * 上传图片
         */
        $upload = new UploadFile();
        $upload_dir = ATTACH_MALBUM.DS.$member_id.DS;

        $upload->set('default_dir',$upload_dir.$upload->getSysSetPath());
        $thumb_width    = '240,1024';
        $thumb_height   = '2048,1024';

        $upload->set('max_size',C('image_max_filesize'));
        $upload->set('thumb_width', $thumb_width);
        $upload->set('thumb_height',$thumb_height);
        $upload->set('fprefix',$member_id);
        $upload->set('thumb_ext', '_240,_1024');
        $result = $upload->upfile('file');
        if (!$result){
            echo json_encode(array('state'=>'false','message'=>Language::get('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
            exit;
        }

        $img_path = $upload->getSysSetPath().$upload->file_name;
        list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH.DS.ATTACH_MALBUM.DS.$member_id.DS.$img_path);

        $image = explode('.', $_FILES["file"]["name"]);


        if(strtoupper(CHARSET) == 'GBK'){
            $image['0'] = Language::getGBK($image['0']);
        }
        $insert = array();
        $insert['ap_name']      = $image['0'];
        $insert['ac_id']        = $class_id;
        $insert['ap_cover']     = $img_path;
        $insert['ap_size']      = intval($_FILES['file']['size']);
        $insert['ap_spec']      = $width.'x'.$height;
        $insert['upload_time']  = time();
        $insert['member_id']    = $member_id;
        $result = $model->table('sns_albumpic')->insert($insert);

        $data = array();
        $data['file_id'] = $result;
        $data['file_name'] = $img_path;
        $data['origin_file_name'] = $_FILES["file"]["name"];
        $data['file_path'] = $img_path;
        $data['file_url'] = snsThumb($img_path, 240);
        $data['state'] = 'true';
        /**
         * 整理为json格式
         */
        $output = json_encode($data);
        echo $output;

    }

}